package pkg

import (
	"fmt"
	"github.com/google/uuid"
	"github.com/smartwalle/alipay/v3"
)

func AliPay(subject, price, orderSn string) string {
	var privateKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiKO097ITTdaThuTOqthYKGBVaVrCW4kbcNfwRnITBY2gIQ3MdgOA3NR92J2bPVQDXR/O3Ih40p9+HRY0Y6zPipbrzzxUAtOEFzcAgho4Rij2bFCQAnRN6sYBEMraUIE973Q4oiSg1ATqB3U/LboVjGpDhahENq39Z3KMVuiwCY2cM6xKRKvE37iNnvvsMKP98cBOpv9fAJCWV9gwoRMV87BgkMcFpscUPAty+mhMpFaFi1pIa93RGrwJKqyQXXHE3Uv8r9jCsfKS9aWZYe8eV6JC2egLhVWPRISjQa7v7+DpaiheUDw2+RhyaT5EjXrcpSgAaIXk38ARz9OklaMI8QIDAQAB" // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	client, err := alipay.New("9021000142616594", privateKey, false)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://6c4dea08.r26.cpolar.top/api/orderCreate"
	p.ReturnURL = "http://6c4dea08.r26.cpolar.top/api/payReturn"
	p.Subject = subject
	p.OutTradeNo = orderSn
	p.TotalAmount = price
	p.ProductCode = uuid.NewString()

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
	}

	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	return payURL
}
